<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of pedido_model
 *
 * @author Neil
 */
class pedido_model extends CI_Model {
    
        public function listadoNotaPedido($cod) {
        $sql = "call sp_listarPedido(?)";
        $query = $this->db->query($sql, $cod);
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila) :
                $data[] = $fila;
            endforeach;
        }else {
            $data = null;
        }
        return $data;
    }

    public function IU_Pedido($oper, $sucOri, $sucDes, $fecha, $codped, $detPedido) {
        $params = array($oper, $sucOri, $sucDes, $fecha, 0);
        $this->db->trans_start();
        $sql = "call sp_IU_Pedido(?,?,?,?,?,@id)";
        $this->db->query("select '$codped' into @id");
        $this->db->query($sql, $params);
        $query = $this->db->query("select @id as codPed");
        $max = $query->row();
        $codPed = str_pad($max->codPed, 7, 0, STR_PAD_LEFT);
        $sql1 = "call sp_I_detallePedido(?,?,?)";
        foreach ($detPedido as $fila) {
            $params2 = array($codPed, $fila->codProd, $fila->cant);
            $this->db->query($sql1, $params2);
        }
        $this->db->trans_complete();
        if ($this->db->trans_status() == FALSE) {
            $msg = 0;
        } else {
            $msg = 1;
        }

        return $msg;
    }

    
}

?>
